/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import Connexion.ConnexionCustomer;
import actions.facade.FacadeAction;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.FinderException;
import miage.beans.CategoriePresentation;
import miage.beans.MagasinPresentation;
import miage.sessions.ecom.remote.EcomCustomerRemote;

/**
 *
 * @author Pepito
 */
public class MagasinAction extends FacadeAction{
    private static EcomCustomerRemote rechercher;
    private List<MagasinPresentation> listMagasinsPresentation = new ArrayList<MagasinPresentation>();
    private List<CategoriePresentation> listCategoriePresentation;

    public List<CategoriePresentation> getListCategoriePresentation() {
        return listCategoriePresentation;
    }

    public void setListCategoriePresentation(List<CategoriePresentation> listCategoriePresentation) {
        this.listCategoriePresentation = listCategoriePresentation;
    }

    public List<MagasinPresentation> getListMagasinsPresentation() {
        return listMagasinsPresentation;
    }

    public void setListMagasinsPresentation(List<MagasinPresentation> listMagasinsPresentation) {
        this.listMagasinsPresentation = listMagasinsPresentation;
    }
    
     public String getListCategorie(){
        try {
            rechercher = ConnexionCustomer.connectionServerBean();
            listCategoriePresentation=rechercher.getAllCategorie();
            return "success";
        } catch (FinderException ex) {
            Logger.getLogger(MagasinAction.class.getName()).log(Level.SEVERE, null, ex);
            return "input";
        } catch (RemoteException ex) {
            Logger.getLogger(MagasinAction.class.getName()).log(Level.SEVERE, null, ex);
            return "input";
       }
    }
            
    @Override
    public String execute(){
        rechercher = (EcomCustomerRemote)ConnexionCustomer.connectionServerBean();
        try {
            listMagasinsPresentation = rechercher.getAllMagasin();
            getListCategorie();
            return "success";
        } catch (FinderException ex) {
            Logger.getLogger(MagasinAction.class.getName()).log(Level.SEVERE, null, ex);
            return "input";
        } catch (RemoteException ex) {
            Logger.getLogger(MagasinAction.class.getName()).log(Level.SEVERE, null, ex);
            return "input";
        }        
    }
}
